import { EventType, IntervalTimeUnit } from "../types/L_Type";
import UnitX from "../entity/UnitX";
import EventExecutor from "./EventExecutor";
import EventGMap from "./EventGMap";
import DotEvent from "./eventdef/DotEvent";
import DotEvemt from "./eventdef/DotEvent";
import EventX from "./eventdef/EventX";
import EnvConfig from "../config/EnvConfig";

/**对所有EventExecutor实现的共通管理  不同间隔类型进行再次抽象管理  优化效率 */
export default class EventManager{
    /**事件队列执行器 管理池  */
    private static executorPool:Record<IntervalTimeUnit,EventExecutor>


    public static init(testMaxRun?:number){
        this.executorPool ={
            'SECONDS':new EventExecutor('SECONDS',testMaxRun),
            'TENTH_OF_SEC':new EventExecutor('TENTH_OF_SEC',testMaxRun),
            'HUNDRE_OF_SEC':new EventExecutor('HUNDRE_OF_SEC',testMaxRun),
            'MILL_SEC':new EventExecutor('MILL_SEC',testMaxRun)
        }
    }

    /**
     * 手动启动所有timer执行器 
     * luaTimer无法自动异步执行所有任务的问题
     */
    public static startExecutorForTest(itu:IntervalTimeUnit){
        // Object.values(this.executorPool).forEach(exc => {
        //     exc.start();
        //   });
        let executor:EventExecutor=this.executorPool[itu]
        if(executor.isRun==false){   //为了解决luaTimer无法异步问题  在事件添加完成后手动调用executor.start()
            executor.start()
        }
    }
 
    public static addEventAndExec(event:EventX){
        let executor:EventExecutor=this.executorPool[event.intervalUnit]
        executor.addEvent(event)   //TODO !!20240724为了使用luaTimer修改调用位置 不确定是否影响jass调用 之前在最后一行
        if(executor.isRun==false && EnvConfig.devMod==false){   //为了解决luaTimer无法异步问题  在事件添加完成后手动调用executor.start()
            executor.start()
        }
       // executor.addEvent(event)
    }


    

  
}  